import Vue from 'vue'
import VueRouter from 'vue-router'
import overview from '../components/Overview.vue'
import userInfo from '../components/UserInfo.vue'
import userSign from '../components/UserSign.vue'
import assetsAdd from '../components/assetsManagement/assetsAdd.vue'
import assetsList from '../components/assetsManagement/assetsList.vue'
import businessConfig from '../components/BusinessConfig.vue'
// 解决侧边栏重复点击的问题
// 获取原型对象上的replace函数
const originalPush = VueRouter.prototype.replace
// 修改原型对象中的replace方法
VueRouter.prototype.replace = function replace(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  {
    path: '/login',  
    component: () => import('../views/Login')
  },
  {
    path:'/home',
    component:()=>import('../views/Home.vue'),
    redirect:'/overview',
    children:[
      {
        path:'/overview',
        name:'overview',
        component:overview,
        meta:{
          requireAuth:true
        }
      },
      {
        path:'/userInfo',
        name:'userInfo',
        component:userInfo,
        meta:{
          requireAuth:true
        }
      },
      {
        path:'/userSign',
        name:'userSign',
        component:userSign,
        meta:{
          requireAuth:true
        }
      },
      {
        path:'/assetsAdd',
        name:'assetsAdd',
        component:assetsAdd,
        meta:{
          requireAuth:true
        }
      },
      {
        path:'/assetsList',
        name:'assetsList',
        component:assetsList,
        meta:{
          requireAuth:true
        }
      },
      {
        path:'/businessConfig',
        name:'businessConfig',
        component:businessConfig,
        meta:{
          requireAuth:true
        }
      }
    ]
  }
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
